<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>动态变更设置 | Elasticsearch: 权威指南 | Elastic</title>
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
</head>
<body>
<div class="main-container">
    <section id="content">
        
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原文地址: <a href="https://www.elastic.co/guide/cn/elasticsearch/guide/current/_changing_settings_dynamically.html" rel="nofollow">https://www.elastic.co/guide/cn/elasticsearch/guide/current/_changing_settings_dynamically.html</a>, 版权归 www.elastic.co 所有<br/>
                            英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/guide/current/_changing_settings_dynamically.html" rel="nofollow">https://www.elastic.co/guide/en/elasticsearch/guide/current/_changing_settings_dynamically.html</a>
                            </div>
                        <!-- start body -->
                  <div class="page_header">
<b>请注意:</b><br>本书基于 Elasticsearch 2.x 版本，有些内容可能已经过时。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch: 权威指南</a></span>
»
<span class="breadcrumb-link"><a href="administration.html">管理、监控和部署</a></span>
»
<span class="breadcrumb-link"><a href="post_deploy.html">部署后</a></span>
»
<span class="breadcrumb-node">动态变更设置</span>
</div>
<div class="navheader">
<span class="prev">
<a href="post_deploy.html">« 部署后</a>
</span>
<span class="next">
<a href="logging.html">日志记录 »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="_changing_settings_dynamically"></a>动态变更设置<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elasticsearch-cn/elasticsearch-definitive-guide/edit/cn/520_Post_Deployment/10_dynamic_settings.asciidoc">edit</a>
</h2>
</div></div></div>
<p>Elasticsearch 里很多设置都是动态的，可以通过 API 修改。

需要强制重启节点（或者集群）的配置修改都要极力避免。

虽然也可以通过静态配置项完成变更，但仍然推荐使用 API。</p>

<p><code class="literal">cluster-update</code> API 有两种工作模式：</p>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
临时的（Transient）
</span>
</dt>
<dd>
这些变更在集群重启之前一直会生效。一旦整个集群重启，这些配置就会被清除。
</dd>
<dt>
<span class="term">
永久的（Persistent）
</span>
</dt>
<dd>
这些变更会永久存在直到被显式修改。
即使整个集群重启它们也会保留下来，并覆盖掉静态配置文件里的选项。
</dd>
</dl>
</div>
<p>临时或永久配置需要在 JSON 体里分别指定：</p>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">PUT /_cluster/settings
{
    "persistent" : {
        "discovery.zen.minimum_master_nodes" : 2 <a id="CO304-1"></a><i class="conum" data-value="1"></i>
    },
    "transient" : {
        "indices.store.throttle.max_bytes_per_sec" : "50mb" <a id="CO304-2"></a><i class="conum" data-value="2"></i>
    }
}</pre>
</div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO304-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p>这个永久设置会在整个集群重启时保留下来。</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO304-2"><i class="conum" data-value="2"></i></a></p>
</td>
<td align="left" valign="top">
<p>这个临时设置会在整个集群第一次重启后被移除。</p>
</td>
</tr>
</table>
</div>
<p>可以动态更新的设置的完整清单，请阅读 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/2.4/cluster-update-settings.html" class="ulink" target="_top">在线参考文档</a>。</p>
</div>
<div class="navfooter">
<span class="prev">
<a href="post_deploy.html">« 部署后</a>
</span>
<span class="next">
<a href="logging.html">日志记录 »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>